//
//  BeforePaymentDetail.m
//  MexicoLoan
//
//  Created by WXP on 2025/3/4.
//
//

#import "ModelBeforePaymentDetail.h"

NSString *const kModelBeforePaymentDetailApplyTime = KEY_applyTime;
NSString *const kModelBeforePaymentDetailLoanAmount = KEY_loanAmount;

@interface ModelBeforePaymentDetail ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ModelBeforePaymentDetail

@synthesize applyTime = _applyTime;
@synthesize loanAmount = _loanAmount;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict {
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if (self && [dict isKindOfClass:[NSDictionary class]]) {
            self.applyTime = [[self objectOrNilForKey:kModelBeforePaymentDetailApplyTime fromDictionary:dict] doubleValue];
            self.loanAmount = [[self objectOrNilForKey:kModelBeforePaymentDetailLoanAmount fromDictionary:dict] doubleValue];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation {
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithDouble:self.applyTime] forKey:kModelBeforePaymentDetailApplyTime];
    [mutableDict setValue:[NSNumber numberWithDouble:self.loanAmount] forKey:kModelBeforePaymentDetailLoanAmount];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description  {
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}

@end
